package Task4;

import java.util.Scanner;

public class Main2 {
    // 任意进制转换
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            int m = scanner.nextInt();
            int n = scanner.nextInt();
            StringBuilder stringBuilder = new StringBuilder();
            //用来判断进制转换
            String str = "0123456789ABCDEF";
            //定义一个标记来记录m是否为负数
            int flag = 0;
            if(m < 0){
                m = -m;
                flag = 1;
            }
            while(m > 0){
                stringBuilder.append(str.charAt(m%n));
                m /= n;
            }
            if(flag == 1){
                stringBuilder.append('-');
            }
            stringBuilder.reverse();
            System.out.println(stringBuilder.toString());
        }
    }
}
